module.exports = {
	/**
	 * 添加单条数据
	 * @url admin/pages/kh/cdkey/add 前端调用的url参数地址
	 * data 请求参数 说明
	 * res 返回参数说明
	 * @params {Number} code 错误码，0表示成功
	 * @params {String} msg 详细信息
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			name,
			type,
			number,
			bean,
			createnumber,
			state,
			buy_state,
			user_id,
			user_nickname,
			used_time,
			remark,
			_add_time,
			_add_time_str
		} = data;
		let res = {
			code: 0,
			msg: 'ok'
		};
		// 业务逻辑开始-----------------------------------------------------------
		// 获取前端传过来的参数
		
		// 参数验证开始

		if (createnumber > 200) {
			res.code = -1;
			res.msg = "单次生成卡密最多200条";
			return res;
		}

		// 参数验证结束
		let dbName = "a_cdkey"; // 表名
		console.log("57============", type);
		console.log("测试====58", type == 4);
		if (type == 4) {
			for (var i = 0; i < createnumber * 1; i++) {
				console.log("金豆卡59======================", type);
				// 执行 数据库add 命令
				res.id = await vk.baseDao.add({
					dbName,
					dataJson: {
						name,
						type,
						bean,
						state,
						buy_state,
						user_id,
						user_nickname,
						used_time,
						remark,
						_add_time,
						_add_time_str
					}
				});
			}


			// 业务逻辑结束-----------------------------------------------------------
			return res;
		} else {

			console.log("会员84=================", type);
			for (var i = 0; i < createnumber * 1; i++) {
				// 执行 数据库add 命令
				res.id = await vk.baseDao.add({
					dbName,
					dataJson: {
						name,
						type,
						number,
						state,
						buy_state,
						user_id,
						user_nickname,
						used_time,
						remark,
						_add_time,
						_add_time_str
					}
				});
			}
			// 业务逻辑结束-----------------------------------------------------------
			return res;
		}
		return res;
	}
}